using Coding4Fun.Phone.Controls;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Shell;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class EditBlogContentPage : BasePage
	{
		private const string TAG = "EditBlogContentPage";
		private string strTypeAndUrl = "";
		private SendCardType mSendCardType;
		private EventWatcher mWatchShareQRCode;
		private bool mBIsLoginFbed;
		private ApplicationBar mBar;
		internal Grid LayoutRoot;
		internal TextBlock txtTitle;
		internal TextBox txtContent;
		private bool _contentLoaded;
		public EditBlogContentPage()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Page_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Page_Unloaded));
			this.setAppBar();
		}
		private void Page_Loaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("EditBlogContentPage", "Page_Loaded");
		}
		private void Page_Unloaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("EditBlogContentPage", "Page_Unloaded");
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("EditBlogContentPage", "OnPageIn");
			if (object_0 != null && object_0.Length != 0)
			{
				if (object_0[0].GetType() == typeof(SendCardType))
				{
					base.get_Dispatcher().BeginInvoke(delegate
					{
						try
						{
							this.txtContent.Focus();
						}
						catch
						{
						}
					});
					this.mSendCardType = (SendCardType)object_0[0];
					this.txtTitle.set_Text((string)object_0[1]);
					this.strTypeAndUrl = (string)object_0[2];
					this.txtContent.set_Text((string)object_0[3]);
					this.initUI();
					this.registerEvent();
					return;
				}
			}
			base.GoBack();
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("EditBlogContentPage", "OnPageOut");
			this.unRegisterEvent();
		}
		protected override void OnPageBack()
		{
			Log.smethod_5("EditBlogContentPage", "OnPageBack");
		}
		private void registerEvent()
		{
			if (this.mWatchShareQRCode == null)
			{
				this.mWatchShareQRCode = new EventWatcher(this, null, new EventHandlerDelegate(this.OnShareQRCode));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_SEND_CARD_SUCCESS, this.mWatchShareQRCode);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_SEND_CARD_ERR, this.mWatchShareQRCode);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchShareQRCode != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_SEND_CARD_SUCCESS, this.mWatchShareQRCode);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_SEND_CARD_ERR, this.mWatchShareQRCode);
				this.mWatchShareQRCode = null;
			}
		}
		private void OnShareQRCode(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			switch (evtArgs.mEventID)
			{
			case EventConst.ON_NETSCENE_SEND_CARD_SUCCESS:
			{
				this.releaseCover();
				ToastPrompt toastPrompt = MessageBoxManager.ShowToast(strings.SendWeibo_Send_Suc, 1000, null, false);
				toastPrompt.Completed += new EventHandler<PopUpEventArgs<string, PopUpResult>>(this.toast_Completed);
				return;
			}
			case EventConst.ON_NETSCENE_SEND_CARD_ERR:
			{
				this.releaseCover();
				RetConst retConst = (RetConst)evtArgs.mObject;
				RetConst retConst2 = retConst;
				if (retConst2 != RetConst.MM_FACEBOOK_ACCESSTOKEN_UNVALID)
				{
					if (retConst2 == RetConst.MM_ERR_NOTOPENPRIVATEMSG)
					{
						MMMessageBox.Show(strings.Setting_NoTentcentWeibo, true, "确定");
						return;
					}
					MMMessageBox.Show(strings.SendWeibo_Send_Error, true, "确定");
					return;
				}
				else
				{
					if (this.mBIsLoginFbed)
					{
						MMMessageBox.Show(strings.SendWeibo_Send_Error, true, "确定");
						return;
					}
					FaceBookLoginPage.ShowFaceBookLoginPage(this, new FaceBookLoginCallBack(this.FaceBookLoginCB), false);
					return;
				}
				break;
			}
			default:
				return;
			}
		}
		public void FaceBookLoginCB(bool isSuccess, string strToken)
		{
			if (!isSuccess)
			{
				return;
			}
			this.mBIsLoginFbed = true;
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.btnFinish_Click(null, null);
			});
		}
		private void toast_Completed(object sender, PopUpEventArgs<string, PopUpResult> e)
		{
			base.GoBack();
		}
		private void txtIn_TextChanged(object sender, TextChangedEventArgs e)
		{
		}
		private void releaseCover()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		private void getCover(string strToShow = null)
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strToShow, null, false, false, null);
		}
		private void initUI()
		{
		}
		private ApplicationBar setAppBar()
		{
			if (this.mBar != null)
			{
				if (!this.mBar.get_IsVisible())
				{
					this.mBar.set_IsVisible(true);
				}
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			ApplicationBarIconButton applicationBarIconButton = new ApplicationBarIconButton(new Uri("/Resource/Img/CommonUse/ico_save.png", 2));
			applicationBarIconButton.set_Text(strings.PCon_Bind_BtnComplete);
			applicationBarIconButton.add_Click(new EventHandler(this.btnFinish_Click));
			this.mBar.get_Buttons().Add(applicationBarIconButton);
			base.set_ApplicationBar(this.mBar);
			this.setAppBarStyle(base.get_ApplicationBar());
			return this.mBar;
		}
		private void btnFinish_Click(object sender, EventArgs e)
		{
			base.Focus();
			SendCardType sendCardType = this.mSendCardType;
			if (sendCardType == SendCardType.MM_SENDCARD_QQBLOG)
			{
				ServiceCenter.sceneSendCard.doScene(this.txtContent.get_Text(), SendCardType.MM_SENDCARD_QQBLOG, 0u, "");
				this.getCover(null);
				return;
			}
			if (sendCardType != SendCardType.MM_SENDCARD_READER)
			{
				return;
			}
			ServiceCenter.sceneSendCard.doScene(this.strTypeAndUrl, SendCardType.MM_SENDCARD_READER, 0u, this.txtContent.get_Text());
			this.getCover(null);
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/TXBlogRead/UI/EditBlogContentPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.txtTitle = (TextBlock)base.FindName("txtTitle");
			this.txtContent = (TextBox)base.FindName("txtContent");
		}
	}
}
